mui.init()

Vue.use(VueLazyload, {
	preLoad: 1.3,
	error: '../../images/noimg.jpg',
	loading: '../../images/noimg.jpg'
});

//这里数据格式复杂,逻辑复杂自己摸索
var shopping = new Vue({
	el: '#shopping',
	data: {
		imgCommonUrl: common.imageUrl,
		shopData: [],
		//是否全选
		selects: 1,
		//总价
		total: 0,
		//编辑状态
		edit: false,
		//编辑是否全选
		selectsedit: 0,
		//重选规格弹窗
		againAlert: false,
		shopDataAlert: '',
		preload: '',
		//local本地存储
		local: false,
		//猜你喜欢
		loveShop: [],
		againAlertData: '',
		backdrop: false
	},

	methods: {
		//店铺选择
		shopDataCheck: function(data) {
			var checkSts = data.checkSts == 1 ? 0 : 1
			//判断是否本地存储
			if(data.local) {
				data.checkSts = checkSts
				for(var i = 0; i < data.cartItems.length; i++) {
					data.cartItems[i].checkSts = data.checkSts
					for(var j = 0; j < data.cartItems[i].shopSpec.length; j++) {
						data.cartItems[i].shopSpec[j].checkSts = data.checkSts
					}
				}
				selects()
			} else {
				var temp = ''
				for(var i = 0; i < data.cartItems.length; i++) {
					for(var j = 0; j < data.cartItems[i].shopSpec.length; j++) {
						temp += data.cartItems[i].shopSpec[j].basketId + ':' + data.cartItems[i].shopSpec[j].prodId + ':' + data.cartItems[i].shopSpec[j].skuId + ':' + checkSts + ';'
					}

				}
				common.ajax('/shopCart/batchChgBasketSts', {
					changeStr: temp.substring(0, temp.length - 1)
				}, function(jsondata) {
					if(jsondata.code == 1) {
						data.checkSts = checkSts
						for(var i = 0; i < data.cartItems.length; i++) {
							data.cartItems[i].checkSts = data.checkSts
							for(var j = 0; j < data.cartItems[i].shopSpec.length; j++) {
								data.cartItems[i].shopSpec[j].checkSts = data.checkSts
							}

						}
						selects()
					} else {
						if(jsondata.resultMsg) {
							common.toast(jsondata.resultMsg)
						}
					}
				}, true)
			}
		},
		//规格选择
		minShopCheck: function(data, child) {
			var checkSts = child.checkSts == 1 ? 0 : 1
			if(child.local) {
				child.checkSts = checkSts
				data.checkSts = 0
				//全部勾上父级勾上
				var num = 0
				var length = 0
				for(var i = 0; i < data.cartItems.length; i++) {
					length++
					for(var j = 0; j < data.cartItems[i].shopSpec.length; j++) {
						length++
						if(data.cartItems[i].shopSpec[j].checkSts == 1) {
							num++
						}
					}
					data.checkSts = length - data.cartItems.length <= num ? 1 : 0
					data.cartItems[i].checkSts = data.checkSts
				}
				selects()
			} else {
				var temp = child.basketId + ':' + child.prodId + ':' + child.skuId + ':' + checkSts
				common.ajax('/shopCart/batchChgBasketSts', {
					changeStr: temp
				}, function(jsondata) {
					if(jsondata.code == 1) {
						child.checkSts = checkSts
						data.checkSts = 0
						//全部勾上父级勾上
						var num = 0
						var length = 0
						for(var i = 0; i < data.cartItems.length; i++) {
							length++
							for(var j = 0; j < data.cartItems[i].shopSpec.length; j++) {
								length++
								if(data.cartItems[i].shopSpec[j].checkSts == 1) {
									num++
								}
							}
							data.checkSts = length - data.cartItems.length <= num ? 1 : 0

						}
						selects()
					} else {
						if(jsondata.resultMsg) {
							common.toast(jsondata.resultMsg)
						}
					}
				}, false)
			}

		},
		//全选
		selectCheck: function() {

			var num = 0
			var tempAjax = ''
			shopping.selects == 1 ? shopping.selects = 0 : shopping.selects = 1
			for(var i = 0; i < shopping.shopData.length; i++) {
				shopping.shopData[i].checkSts = shopping.selects
				for(var j = 0; j < shopping.shopData[i].cartItems.length; j++) {
					shopping.shopData[i].cartItems[j].checkSts = shopping.selects
					for(var c = 0; c < shopping.shopData[i].cartItems[j].shopSpec.length; c++) {
						shopping.shopData[i].cartItems[j].shopSpec[c].checkSts = shopping.selects
						var promotionPrice = shopping.shopData[i].cartItems[j].shopSpec[c].promotionPrice == '' || shopping.shopData[i].cartItems[j].shopSpec[c].promotionPrice == 0 ? shopping.shopData[i].cartItems[j].shopSpec[c].price : shopping.shopData[i].cartItems[j].shopSpec[c].promotionPrice
						num += promotionPrice * shopping.shopData[i].cartItems[j].shopSpec[c].basketCount
						tempAjax += shopping.shopData[i].cartItems[j].shopSpec[c].basketId + ':' + shopping.shopData[i].cartItems[j].shopSpec[c].prodId + ':' + shopping.shopData[i].cartItems[j].shopSpec[c].skuId + ':' + shopping.selects + ';'
					}
				}
			}
			shopping.total = shopping.selects == 1 ? num : 0
			if(shopping.local) {
				localStorage.setItem('shopPingCar', JSON.stringify(shopping.shopData))
			} else {
				common.ajax('/shopCart/batchChgBasketSts', {
					changeStr: tempAjax.substring(0, tempAjax.length - 1)
				}, function(jsondata) {
					if(jsondata.code == 1) {

					} else {
						if(jsondata.resultMsg) {
							common.toast(jsondata.resultMsg)
						}
					}
				}, true)
			}

		},
		//		加减
		reduce: function(child, data) {
			if(child.basketCount <= 1) {
				return
			}
			//			var wt=plus.nativeUI.showWaiting();
			//			wt.close()
			if(child.local) {
				child.basketCount--
					localStorage.setItem('shopPingCar', JSON.stringify(shopping.shopData))
				selects()
			} else {
				var num = child.basketCount
				common.jsonAjax('/shopCart/changeShopCartNum', {
					basketId: child.basketId,
					num: --num,
					prodId: child.prodId,
					skuId: child.skuId,
					type: 1
				}, function(data) {
					if(data.code == 1) {
						child.basketCount--
							selects()
						console.log("修改成功")
					} else {
						if(data.resultMsg) {
							common.toast(data.resultMsg)
						}
					}
				}, true)
			}
		},
		reduceShopNum: function(child, data) {
			child.basketCount = child.basketCount.replace(/[^0-9]/g, '')

			if(child.basketCount <= 1 && child.basketCount != '') {
				child.basketCount = 1
			}
			if(child.basketCount == '') {
				return
			}

			if(child.local) {
				if(child.basketCount > child.stocks) {
					child.basketCount = child.stocks
					common.toast("库存不足")
				}
				selects()
			} else {
				//			var wt=plus.nativeUI.showWaiting();
				//			wt.close()
				var num = child.basketCount
				common.jsonAjax('/shopCart/changeShopCartNum', {
					basketId: child.basketId,
					num: num,
					prodId: child.prodId,
					skuId: child.skuId,
					type: 1
				}, function(data) {
					if(data.code == 1) {
						selects()
						console.log("修改成功")
					} else {
						child.basketCount = child.basketCount.substring(0, child.basketCount.length - 1)
						if(data.resultMsg) {
							common.toast(data.resultMsg)
						}
					}
				}, true)
			}
		},
		add: function(child, data) {
			if(child.local) {
				if(child.basketCount < child.stocks) {
					child.basketCount++
				} else {
					child.basketCount = child.stocks
					common.toast("库存不足")
				}
				selects()
			} else {
				//			var wt=plus.nativeUI.showWaiting();
				//			wt.close()
				var num = child.basketCount
				common.jsonAjax('/shopCart/changeShopCartNum', {
					basketId: child.basketId,
					num: ++num,
					prodId: child.prodId,
					skuId: child.skuId,
					type: 1
				}, function(data) {
					if(data.code == 1) {
						child.basketCount++
							selects()
						console.log("修改成功")
					} else {
						if(data.resultMsg) {
							common.toast(data.resultMsg)
						}
					}
				}, true)
			}
		},
		//编辑切换
		editSwith: function() {
			if(shopping.shopData.length == 0) {
				shopping.edit = false
				return
			}
			shopping.edit = !shopping.edit
			shopping.selectsedit = 0
			totalEdit()
		},
		//店铺编辑选择
		shopDataEditCheck: function(data) {
			data.edit == 1 ? data.edit = 0 : data.edit = 1
			for(var i = 0; i < data.cartItems.length; i++) {
				data.cartItems[i].edit = data.edit
				for(var j = 0; j < data.cartItems[i].shopSpec.length; j++) {
					data.cartItems[i].shopSpec[j].edit = data.edit
				}
			}
			selectsEdit()
		},
		//编辑规格选择
		minShopEditCheck: function(data, child) {
			child.edit == 1 ? child.edit = 0 : child.edit = 1
			data.edit = 0
			//全部勾上父级勾上
			var num = 0
			var length = 0
			for(var i = 0; i < data.cartItems.length; i++) {
				length++
				for(var j = 0; j < data.cartItems[i].shopSpec.length; j++) {
					length++
					if(data.cartItems[i].shopSpec[j].edit == 1) {
						num++
					}
				}
				data.edit = length - data.cartItems.length <= num ? 1 : 0

			}

			selectsEdit()
		},
		//编辑全选
		selectEditCheck: function() {
			shopping.selectsedit == 1 ? shopping.selectsedit = 0 : shopping.selectsedit = 1
			totalEdit()
		},
		//删除
		removeShop: function() {

			if(shopping.local) {
				for(var i = 0; i < shopping.shopData.length; i++) {
					if(shopping.shopData[i].edit == 1) {
						shopping.shopData.splice(i--, 1)
					} else {
						for(var j = 0; j < shopping.shopData[i].cartItems.length; j++) {
							if(shopping.shopData[i].cartItems[j].edit == 1) {
								shopping.shopData[i].cartItems.splice(j--, 1)
							} else {
								for(var c = 0; c < shopping.shopData[i].cartItems[j].shopSpec.length; c++) {
									if(shopping.shopData[i].cartItems[j].shopSpec[c].edit == 1) {
										shopping.shopData[i].cartItems[j].shopSpec.splice(c--, 1)
										//没规格删除商品
										if(shopping.shopData[i].cartItems[j].shopSpec.length <= 0) {
											shopping.shopData[i].cartItems.splice(j, 1)
										}
									}
								}
							}

						}
					}
				}
				if(shopping.shopData.length == 0) {
					shopping.edit = false
				}
				selectsEdit()
				selects()
			} else {
				var temp = ''
				for(var i = 0; i < shopping.shopData.length; i++) {
					for(var j = 0; j < shopping.shopData[i].cartItems.length; j++) {
						for(var c = 0; c < shopping.shopData[i].cartItems[j].shopSpec.length; c++) {
							if(shopping.shopData[i].cartItems[j].shopSpec[c].edit == 1) {
								temp += shopping.shopData[i].cartItems[j].shopSpec[c].basketId + ';'
							}
						}
					}
				}
				common.ajax('/shopCart/deleteShopCart', {
					basketId: temp.substring(0, temp.length - 1)
				}, function(data) {
					if(data.code == 1) {

						for(var i = 0; i < shopping.shopData.length; i++) {
							if(shopping.shopData[i].edit == 1) {
								shopping.shopData.splice(i--, 1)
							} else {
								for(var j = 0; j < shopping.shopData[i].cartItems.length; j++) {
									if(shopping.shopData[i].cartItems[j].edit == 1) {
										shopping.shopData[i].cartItems.splice(j--, 1)
									} else {
										for(var c = 0; c < shopping.shopData[i].cartItems[j].shopSpec.length; c++) {
											if(shopping.shopData[i].cartItems[j].shopSpec[c].edit == 1) {
												shopping.shopData[i].cartItems[j].shopSpec.splice(c--, 1)
												//没规格删除商品
												if(shopping.shopData[i].cartItems[j].shopSpec.length <= 0) {
													shopping.shopData[i].cartItems.splice(j, 1)
												}
											}
										}
									}

								}
							}
						}
						if(shopping.shopData.length == 0) {
							shopping.edit = false
						}
						selectsEdit()
						selects()

					} else {
						if(data.resultMsg) {
							common.toast(data.resultMsg)
						}
					}
				}, true)
			}

		},
		//		重新选择规格
		againAlertTap: function(data) {
			shopping.againAlertData = data
			shopping.preload = data.prodId
			common.ajax('/category/classifyProDetail/' + data.prodId, {}, function(dataJson) {
				if(dataJson.code == 1) {
					for(var i = 0; i < dataJson.data.prod.skuDtoList.length; i++) {
						for(var j = 0; j < data.shopSpec.length; j++) {
							if(dataJson.data.prod.skuDtoList[i].skuId == data.shopSpec[j].skuId) {
								dataJson.data.prod.skuDtoList[i].num = data.shopSpec[j].basketCount
								break
							} else {
								dataJson.data.prod.skuDtoList[i].num = 0
							}
							dataJson.data.prod.skuDtoList[i].num = 0
						}
					}
					shopping.againAlert = true
					shopping.shopDataAlert = dataJson.data.prod
				} else {
					if(dataJson.resultMsg) {
						common.toast(dataJson.resultMsg)
					}
				}
			}, false, 'get')

		},
		closeAgainAlertTap: function() {
			//			$("body").css('overflow-y', 'scroll')
			shopping.againAlert = false
		},

		inputNum: function(data) {
			data.num = data.num.replace(/[^0-9]/g, '')
			if(data.num > data.stocks) {
				data.num = data.stocks
				common.toast("库存不足")
			} else if(data.num <= 0 && data.num != '') {
				data.num = 0
			}
		},

		addShop: function(data) {
			if(data.num < data.stocks) {
				data.num++
			} else {
				data.num = data.stocks
				common.toast("库存不足")
			}
		},
		reduceShop: function(data) {
			if(data.num > 0) {
				data.num--
			}
		},
		addShopBuy: function() {
			if(shopping.local) {
				for(var i = 0; i < shopping.shopData.length; i++) {
					if(shopping.shopData[i].proId == shopping.preload) {
						for(var j = 0; j < shopping.shopData[i].cartItems.length; j++) {
							for(var c = 0; c < shopping.shopData[i].cartItems[j].shopSpec.length; c++) {

								for(var d = 0; d < shopping.shopDataAlert.skuDtoList.length; d++) {

									//判断同不同规格,同规格就加数量,否则就添加一个规格
									if(shopping.shopData[i].cartItems[j].shopSpec[c].skuId == shopping.shopDataAlert.skuDtoList[d].skuId) {
										if(shopping.shopDataAlert.skuDtoList[d].num > 0) {
											shopping.shopData[i].cartItems[j].shopSpec[c].basketCount = Number(shopping.shopDataAlert.skuDtoList[d].num)
										}
									} else {
										if(shopping.shopDataAlert.skuDtoList[d].num > 0) {
											var basketId = '"basketId":' + shopping.shopDataAlert.skuDtoList[d].skuId
											if(JSON.stringify(shopping.shopData).indexOf(basketId) < 0) {
												shopping.shopDataAlert.skuDtoList[d].basketCount = shopping.shopDataAlert.skuDtoList[d].num
												shopping.shopDataAlert.skuDtoList[d].basketId = shopping.shopDataAlert.skuDtoList[d].skuId
												shopping.shopDataAlert.skuDtoList[d].promotionPrice = ''
												shopping.shopDataAlert.skuDtoList[d].checkSts = 1
												shopping.shopDataAlert.skuDtoList[d].edit = 0
												shopping.shopDataAlert.skuDtoList[d].local = true
												shopping.shopDataAlert.skuDtoList[d].cnProperties = shopping.shopDataAlert.skuDtoList[d].cn_properties
												shopping.shopData[i].cartItems[j].shopSpec.push(shopping.shopDataAlert.skuDtoList[d])
												shopping.shopDataAlert.skuDtoList[d].num = 0
											}
										}
									}
								}
							}
						}
					}
				}
				common.toast('添加成功')
				localStorage.setItem('shopPingCar', JSON.stringify(shopping.shopData))
				shopping.againAlert = false
				for(var i = 0; i < shopping.shopDataAlert.skuDtoList.length; i++) {
					shopping.shopDataAlert.skuDtoList[i].num = 0
				}
			} else {
				var temp = ''
				for(var i = 0; i < shopping.shopDataAlert.skuDtoList.length; i++) {
					if(shopping.shopDataAlert.skuDtoList[i].num > 0) {
						temp += shopping.shopDataAlert.skuDtoList[i].skuId + ':' + shopping.shopDataAlert.skuDtoList[i].num + ','
					}
				}

				if(temp == '') {
					common.toast('请选择商品')
					return
				}
				common.jsonAjax('/shopCart/changeShopCartNum', {
					basketId: shopping.againAlertData.basketId,
					prodId: shopping.againAlertData.prodId,
					skuIds: temp.substring(0, temp.length - 1),
					type: 1,
					num: 0
				}, function(data) {
					if(data.code == 1) {
						ajaxData()
						common.toast('添加成功')
						shopping.againAlert = false
					} else {
						if(data.resultMsg) {
							mui.toast(data.resultMsg)
						}
					}
				})
			}

		},
		openDetails: function(data) {
			common.open('../details/details.html', '../details/details.html', data.prodId)
		},
		//逛一逛
		goShoping: function() {
			var list = plus.webview.getWebviewById("ylindex.html")
			mui.fire(list, 'gohome');
		},
		//去结算
		goSettlement: function() {
			if(JSON.parse(localStorage.getItem('userData'))) {
				var temp = ''
				for(var i = 0; i < shopping.shopData.length; i++) {
					for(var c = 0; c < shopping.shopData[i].cartItems.length; c++) {
						for(var j = 0; j < shopping.shopData[i].cartItems[c].shopSpec.length; j++) {
							if(shopping.shopData[i].cartItems[c].shopSpec[j].checkSts == 1) {
								temp += shopping.shopData[i].cartItems[c].shopSpec[j].basketId + ','
							}
						}
					}
				}
				if(temp == '') {
					common.toast('没有选择商品')
					return
				}
				common.open('../order/confirmorder.html', '../order/confirmorder.html', temp.substring(0, temp.length - 1))
			} else {
				common.open('../login/login.html', '../login/login.html')
			}
		},
		addShopCar: function(data) {
			mui.plusReady(function() {
				shopping.backdrop = true
				var w = plus.webview.create('../mask/clsaddcart.html', '../mask/clsaddcart.html', {
					top: '40%',
					bottom: '0'
				}, {
					preload: data.prodId
				});
				w.show('slide-in-bottom'); // 显示窗口
			})
		}
	},
	watch: {
		total: function(newdata, olddata) {
			this.total = Number(newdata).toFixed(2)
		},
		shopData: function(newdata, olddata) {
			if(newdata.length <= 0) {
				shopping.$nextTick(function() {
					$(".advert_five_img").height($(".advert_five_img").width())
				})
			}

		}
	}
})

ajaxData()

function ajaxData() {
	common.ajax('/shopCart/getData', {}, function(data) {
		if(data.code == 1) {
			shopping.loveShop = data.data.likes
			shopping.$nextTick(function() {
				$(".advert_five_img").height($(".advert_five_img").width())
			})
			if(!data.data.userShopCartList) {
				if(localStorage.getItem('shopPingCar')) {
					shopping.shopData = JSON.parse(localStorage.getItem('shopPingCar'))
					shopping.local = true
					selects()
				}
				return
			}
			for(var i = 0; i < data.data.userShopCartList.shopCarts.length; i++) {
				var temp = []
				var prodId = []
				//				全选择
				data.data.userShopCartList.checkSts = 1
				data.data.userShopCartList.edit = 0
				//大模块是否选中
				data.data.userShopCartList.shopCarts[i].checkSts = 1
				data.data.userShopCartList.shopCarts[i].edit = 0
				//循环排序规格
				for(var j = 0; j < data.data.userShopCartList.shopCarts[i].cartItems.length; j++) {
					if(prodId.indexOf(data.data.userShopCartList.shopCarts[i].cartItems[j].prodId) < 0) {
						prodId.push(data.data.userShopCartList.shopCarts[i].cartItems[j].prodId)
						data.data.userShopCartList.shopCarts[i].cartItems[j].shopSpec = []

						data.data.userShopCartList.shopCarts[i].cartItems[j].shopSpec.push(JSON.parse(JSON.stringify(data.data.userShopCartList.shopCarts[i].cartItems[j])))
						temp.push(data.data.userShopCartList.shopCarts[i].cartItems[j])
					} else {
						for(var c = 0; c < temp.length; c++) {
							if(temp[c].prodId == data.data.userShopCartList.shopCarts[i].cartItems[j].prodId) {
								temp[c].shopSpec.push(data.data.userShopCartList.shopCarts[i].cartItems[j])
							}
						}
					}
					data.data.userShopCartList.shopCarts[i].cartItems[j].edit = 0
					if(data.data.userShopCartList.shopCarts[i].checkSts == 0) {
						shopping.selects = 0
					}
				}
				//规格选择
				var checkNum = 0
				for(var d = 0; d < data.data.userShopCartList.shopCarts[i].cartItems.length; d++) {
					data.data.userShopCartList.shopCarts[i].checkSts = 0
					if(data.data.userShopCartList.shopCarts[i].cartItems[d].checkSts == 1) {
						checkNum++
						data.data.userShopCartList.shopCarts[i].checkSts = data.data.userShopCartList.shopCarts[i].cartItems.length <= checkNum ? 1 : 0
					}
				}

				data.data.userShopCartList.shopCarts[i].cartItems = temp
			}
			shopping.shopData = data.data.userShopCartList.shopCarts
			selects()
		} else {
			if(data.resultMsg) {
				common.toast(data.resultMsg)
			}
		}
	}, false, 'get')
}

//计算价格和勾选
function selects() {
	shopping.selects = 1
	var num = 0
	for(var i = 0; i < shopping.shopData.length; i++) {
		if(shopping.shopData[i].checkSts == 0) {
			shopping.selects = 0
		}
		for(var j = 0; j < shopping.shopData[i].cartItems.length; j++) {
			//			if(shopping.shopData[i].cartItems[j].checkSts == 0) {
			//				shopping.selects = 0
			//			}
			for(var c = 0; c < shopping.shopData[i].cartItems[j].shopSpec.length; c++) {
				if(shopping.shopData[i].cartItems[j].shopSpec[c].checkSts == 0) {
					shopping.selects = 0
				} else {
					var promotionPrice = shopping.shopData[i].cartItems[j].shopSpec[c].promotionPrice == '' || shopping.shopData[i].cartItems[j].shopSpec[c].promotionPrice == 0 ? shopping.shopData[i].cartItems[j].shopSpec[c].price : shopping.shopData[i].cartItems[j].shopSpec[c].promotionPrice
					num += promotionPrice * shopping.shopData[i].cartItems[j].shopSpec[c].basketCount
				}
			}
		}
	}
	shopping.total = num
	if(shopping.local) {
		localStorage.setItem('shopPingCar', JSON.stringify(shopping.shopData))
	}
}
//编辑是否全选
function selectsEdit() {
	shopping.selectsedit = 1
	for(var i = 0; i < shopping.shopData.length; i++) {
		if(shopping.shopData[i].edit == 0) {
			shopping.selectsedit = 0
		}
		for(var j = 0; j < shopping.shopData[i].cartItems.length; j++) {
			//			if(shopping.shopData[i].cartItems[j].edit == 0) {
			//				shopping.selectsedit = 0
			//			}
			for(var c = 0; c < shopping.shopData[i].cartItems[j].shopSpec.length; c++) {
				if(shopping.shopData[i].cartItems[j].shopSpec[c].edit == 0) {
					shopping.selectsedit = 0
				}
			}
		}
	}
}

function totalEdit() {
	for(var i = 0; i < shopping.shopData.length; i++) {
		shopping.shopData[i].edit = shopping.selectsedit
		for(var j = 0; j < shopping.shopData[i].cartItems.length; j++) {
			shopping.shopData[i].cartItems[j].edit = shopping.selectsedit
			for(var c = 0; c < shopping.shopData[i].cartItems[j].shopSpec.length; c++) {
				shopping.shopData[i].cartItems[j].shopSpec[c].edit = shopping.selectsedit
			}
		}
	}
}

$('.mui-backdrop').bind("touchmove", function(e) {
	e.preventDefault();
});
$('.mui-backdrop').bind("touchstart", function(e) {
	e.preventDefault();
});

//var height = document.documentElement.clientHeight || document.body.clientHeight;
//window.onresize = function() {
//	var heightView = document.documentElement.clientHeight || document.body.clientHeight;
//	if(heightView < height) {
//
//		plus.webview.getWebviewById('ylindex.html').setStyle({
//			height: (height + 51)
//		});
//		plus.webview.currentWebview().setStyle({
//			height: heightView
//		});
//	} else {
//		plus.webview.getWebviewById('ylindex.html').setStyle({
//			height: (height + 51)
//		});
//		plus.webview.currentWebview().setStyle({
//			height: heightView
//		});
//		
//	}
//	console.log(11)
//}

if(mui.os.ios) {
	$(document).on('focus', '.collection_num input', function() {
		setTimeout(setHe, 100)
	})
}

function setHe() {
	document.body.scrollTop = document.body.scrollHeight
}

window.addEventListener('hideMask', function() {
	shopping.backdrop = false
});

window.addEventListener('refreshs', function() {
	ajaxData()
});

var close = mui.back
var _toast = false
mui.back = function() {
	if(shopping.backdrop) {
		shopping.backdrop = false
		plus.webview.close('../mask/clsaddcart.html');
	} else {
		if(!_toast || !_toast.isVisible()) {
			_toast = mui.toast('再按一次返回键退出', {
				type: 'div'
			});
		} else {
			var main = plus.android.runtimeMainActivity();
			main.moveTaskToBack(false);
		}
	}
}